package com.satan.elasticsearch.doc;

import com.satan.elasticsearch.dao.entity.Hotel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class HotelDoc {
    @Schema(description = "酒店id")
    private Long id;
    @Schema(description = "酒店名称")
    private String name;
    @Schema(description = "酒店地址")
    private String address;
    @Schema(description = "酒店价格")
    private Integer price;
    @Schema(description = "酒店评分")
    private Integer score;
    @Schema(description = "酒店品牌")
    private String brand;
    @Schema(description = "酒店城市")
    private String city;
    @Schema(description = "酒店星级")
    private String starName;
    @Schema(description = "酒店商圈")
    private String business;
    @Schema(description = "酒店经纬度")
    private String location;
    @Schema(description = "酒店图片")
    private String pic;
    // 排序时的 距离值
    @Schema(description = "距离值")
    private Object distance;
    @Schema(description = "是否广告位")
    private Boolean isAD;
    @Schema(description = "建议词")
    private List<String> suggestion;

    public HotelDoc(Hotel hotel) {
        this.id = hotel.getId();
        this.name = hotel.getName();
        this.address = hotel.getAddress();
        this.price = hotel.getPrice();
        this.score = hotel.getScore();
        this.brand = hotel.getBrand();
        this.city = hotel.getCity();
        this.starName = hotel.getStarName();
        this.business = hotel.getBusiness();
        this.location = hotel.getLatitude() + ", " + hotel.getLongitude();
        this.pic = hotel.getPic();
        final String regex = "[\\u4e00-\\u9fa5]+";
        final Pattern pattern = Pattern.compile(regex);
        if (hotel.getBusiness().isEmpty()) {
            this.suggestion = Arrays.asList(this.brand);
        } else {
            this.suggestion = new ArrayList<>();
            this.suggestion.add(this.brand);
            Matcher matcher = pattern.matcher(hotel.getBusiness());
            while (matcher.find()) {
                this.suggestion.add(matcher.group());
            }
        }

    }
}
